

const userModel = require('../lib/user.js');
const moment = require('moment');

exports.getRegister = async ctx => {
  await ctx.render('register', {
    session: ctx.session,
  })
}
exports.postRegister = async ctx => {
  let { name,password } = ctx.request.body
  var result = await userModel.findDataByName(name)
  if(result.length && name == result[0]['name']){
    ctx.body = {
      code: 401,
      message: '用户名已被占用'
    };
    return;
  }
  
  var result2 = await userModel.insertData([name, password, moment().format('YYYY-MM-DD HH:mm:ss')])
  if(result2){
    ctx.body = {
      code: 200,
      message: '注册成功'
    };
  }
}